package com.lin.missyou.api.v1;

import com.lin.missyou.core.interceptors.ScopeLevel;
import com.lin.missyou.exception.http.NotFoundException;
import com.lin.missyou.model.Banner;
import com.lin.missyou.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @author gcq
 * @Create 2021-09-28
 */
@RestController
@RequestMapping("/banner")
@Validated
public class BannerController {

    @Autowired
    BannerService bannerService;

    /**
     * 返回json
     *  如果是空值 那么应该
     * @param name
     * @return
     */
    @GetMapping("/name/{name}")
    @ScopeLevel()
    public Banner getByName(@PathVariable @NotBlank String name)
    {
        Banner byName = bannerService.getByName(name);
        if(byName == null){
            throw new NotFoundException(30005);
        }
        return byName;
    }
}